Chris Pollett >
Old Classses > |
HW#3 --- last modified February 07 2019 04:20:45..Due date: Nov 3
Files to be submitted: Purpose: To write a CSP solver for Sudoku. To learn more about logic-based agents. Related Course Outcomes: The main course outcomes covered by this assignment are: LO2 -- By code or by hand translate sentences in logic to conjunctive normal form (CNF). LO3 -- By code or by hand find proofs by using resolution. LO7 -- Students should be able to explain the advantages and disadvantages of forward checking in constraint satisfaction. Specification: This homework will consist of two parts: Some written questions and a coding part. You are to write up your written questions in a file Hw3.pdf which you include as part of the zip file. Make sure to list all group members and their IDs at the top of this file. Here are the written questions:
For the programming portion of this assignment, you are to write a CSP solver which will be run from the command line with a syntax like: python csp_solver.py problem_filename use_forward_check_flag Here problem_filename is the name of some text file containing a CSP using the syntax we now describe. use_forward_check_flag is either 1 or 0 and determines whether forward checking is used. A legal file will consists of a sequence of lines each representing one constraint. A given line has the syntax: Variable Rel Var_Or_Integer The separator between each item above is a single space character and a line is terminated by a newline character. A Variable is a string beginning with either a lower lower or upper case letter followed by any number of lower or upper case letters or numbers or underscores. For example, X5 -- A variable l33t_Pr0Gr4mm0r -- A variable 5 -- Not a variable $perl_nerd -- Not a variable as begins with dollars SA -- A variable NSW -- A variable Rel is one of eq, ne, lt, gt representing the equals, not equals, less than, or greater than relations. Finally, Var_Or_Integer can either be a variable or a nonnegative integer. Here are some example legal lines: SA ne NSW bob eq 27 Ewoks lt Yoda Given such a legal file, your program should first make a scan of the file to determine the number `D` of distinct variables in the file as well as the largest value `V` of an integer in a constraint. The CSP then consists of the relations given in the file where each variable has domain `0, 1, ... max(D-1,V)`. Given this CSP your program should run the backtracking procedure described in class. SELECT-UNASSIGNED VARIABLES should implement the MRV and degree heuristics, ORDER-DOMAIN-VALUES should implement the least-constraining-value heuristic. INFERENCES should either return the empty assignment or should do forward checking depending on the command line option. The output of your program should be either "NO SOLUTION" or a sequence of lines each containing one variable assignment in a solving the problem. The variables should be output in lexicographical order. You should include the test files you create for this homework in the ZIP folder. At least one of these test files should be a formulation of the map coloring of Australia problem from the book where we let red = 0, green = 1, blue = 2. Here is an example for this problem of a possible output: NSW=2 NT=2 Q=1 SA=0 T=0 V=1 WA=1 Consider the smaller map, consisting of three countries: Shortz -- as it looks like a pair of shorts, ME -- Middle Earth, Uland -- as it is shaped like a U. Coloring this map could be expressed as follows: ME ne Shortz ME ne Uland Uland ne Shortz On this input your program should output: ME=0 Shortz=1 Uland=2 You should conduct some experiments related to the effectiveness and overhead of forward checking. Write these up in a file Experiments.pdf which you also include in your ZIP file. Point Breakdown
|